
package com.ukao.cashregister.pesenter;

import com.ukao.cashregister.base.BasePresenter;
import com.ukao.cashregister.bean.AccountLoginBean;
import com.ukao.cashregister.bean.TokenBean;
import com.ukao.cashregister.consts.Constant;
import com.ukao.cashregister.retrofit.ApiCallback;
import com.ukao.cashregister.utils.ThreadUtils;
import com.ukao.cashregister.view.SwipingCardLoginView;

import java.util.HashMap;

/**
 * Created by ukaodev on 2017/6/28.
 */

public class SwipingCardLoginPesenter extends BasePresenter<SwipingCardLoginView> {
    private boolean isloaderr;

    public SwipingCardLoginPesenter(SwipingCardLoginView view) {
        attachView(view);
    }


    public void appSecretData(     ) {
        ThreadUtils.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                mvpView.showLoading();
                isloaderr=false;
                HashMap mHashMap = new HashMap<String, String>();
                addSubscription(apiStores.getToken(Constant.firstParameter(mHashMap)),
                        new ApiCallback<TokenBean>() {
                            @Override
                            public void onSuccess(TokenBean model) {

                                if (model.getHttpCode() == 200) {

                                    mvpView.appSecretSucceed(model);
                                }else{

                                    mvpView.loadFailure(model.getMsg());
                                }

                            }


                            @Override
                            public void onFinish() {
                                mvpView.hideLoading();


                            }
                        });
            }
        });

    }






    public void swipingCardlogin(String  rfidSecret  ) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("rfidSecret", rfidSecret);
        addSubscription(apiStores.swipingCardlogin(Constant.createParameter(mHashMap)),
                new ApiCallback<AccountLoginBean>() {
                    @Override
                    public void onSuccess(AccountLoginBean model) {
                        if (model.getHttpCode()==200){
                             AccountLoginBean mitem = model.getData();
                              mvpView.loadloginSucceed(mitem);

                        }else{
                            mvpView.loadFailure(model.getMsg());
                        }
                    }



                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();

                    }
                });
    }



}
